<template>
  <div>
    <a-modal
      title="创建分组"
      :visible="visible"
      @ok="handleOk"
      :confirmLoading="confirmLoading"
      @cancel="handleCancel"
      width="370px">
      <a-row>
        <a-input placeholder="创建分组" v-model="name" @change="onChange" style="margin-bottom: 10px;"/>
        <a-input-number :min="1" placeholder="排序" v-model="sort" style="width: 100%;" />
      </a-row>
      <a-divider dashed />
    </a-modal>
  </div>
</template>
<script>
  import {
    addGroup
  } from '@/api/site/upFile'
  export default {
    data () {
      return {
        visible: false,
        confirmLoading: false,
        name: null,
        sort: 0
      }
    },
    methods: {
      add () {
        this.visible = true
      },
      handleOk (e) {
        if (!this.name) {
          this.$message.error('分组名称不能为空!')
          return
        }
        addGroup({ name: this.name, sort: this.sort }).then(response => {
          if (response.code === 0) {
            this.$emit('ok')
            this.handleCancel()
            this.$message.info(response.msg)
          } else {
            this.$message.error(response.msg)
          }
        })
      },
      handleCancel (e) {
        this.name = null
        this.sort = 1
        this.visible = false
      },
      onChange (e) {

      }
    }
  }
</script>
